home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / test / filesys.sml < prev    next >
Encoding:
Text File  |  1996-07-03  |  4.6 KB  |  147 lines  |  [TEXT/R*ch]

  1. (* test/filesys.sml
  2.    PS 1995-03-23
  3. *)
  4.  
  5. (* DOS: Plain WRONG: test6a, test9a (and test9b);
  6.         Excusable:   test8b, test11b, test12a, test13a, test13b, test13c
  7.  *)
  8.  
  9. (* This requires two links to be present in the current directory:
  10.     testlink -> README
  11.     testcycl -> testcycl 
  12.     testbadl -> exists.not
  13.    Moreover, the file README must exist and the file exists.not not.
  14. *)
  15.  
  16.  
  17. use "auxil.sml";
  18.  
  19. local
  20.     open FileSys
  21.     (* Clean up: *)
  22.     val _ = (rmDir "testdir") handle OS.SysErr _ => (); 
  23.     val _ = (rmDir "testdir2") handle OS.SysErr _ => (); 
  24. in
  25.  
  26. val test1a = (mkDir "testdir" seq "OK") handle _ => "WRONG";
  27. val test1b = (mkDir "testdir" seq "WRONG")
  28.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  29.  
  30. val test2 = check'(fn _ => isDir "testdir");
  31.     
  32. val test3 = check'(fn _ => access("testdir", [A_READ, A_EXEC, A_WRITE]));
  33.  
  34. local 
  35.     val cdir = getDir();
  36. in
  37.     val test4a = (chDir cdir seq "OK") handle _ => "WRONG";
  38.     val test4b = check'(fn _ => cdir = getDir());
  39.     val _ = chDir "testdir";
  40.     val test4c = check'(fn _ => cdir <> getDir());
  41.     val _ = chDir "..";
  42.     val test4d = check'(fn _ => cdir = getDir());
  43. end;
  44.  
  45. val _ = rename{old = "testdir", new = "exists.not"};
  46.  
  47. val test5 = (rmDir "exists.not" seq "OK") handle _ => "WRONG";
  48.  
  49. val test6a = (openDir "exists.not" seq "WRONG") 
  50.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  51. val test6b = (isDir "exists.not" seq "WRONG")
  52.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  53. val test6c = (rmDir "exists.not" seq "WRONG")
  54.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  55. val test6d = (chDir "exists.not" seq "WRONG")
  56.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  57. val test6e = (realPath "exists.not" seq "WRONG")
  58.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  59. val test6f = (modTime "exists.not" seq "WRONG")
  60.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  61. val test6g = (setTime("exists.not", NONE) seq "WRONG")
  62.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  63. val test6h = (remove "exists.not" seq "WRONG")
  64.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  65. val test6i = (rename{old="exists.not", new="testdir2"} seq "WRONG")
  66.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  67. val test6j = check'(fn _ => not (access("exists.not", [])));
  68.  
  69. val _ = mkDir "testdir";
  70.  
  71. local 
  72.     val dstr = openDir "testdir";
  73. in
  74.     val test7a = 
  75.     check'(fn _ => "." = readDir dstr
  76.            andalso ".." = readDir dstr
  77.            andalso "" = readDir dstr);
  78.     val _ = rewindDir dstr;
  79.     val test7b = 
  80.     check'(fn _ => "." = readDir dstr
  81.            andalso ".." = readDir dstr
  82.            andalso "" = readDir dstr);
  83.     val _ = closeDir dstr;
  84.     val test7c = (readDir dstr seq "WRONG")
  85.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  86.     val test7d = (rewindDir dstr seq "WRONG")
  87.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  88.     val test7e = (closeDir dstr seq "WRONG")
  89.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  90. end
  91.  
  92. val test8a = 
  93.     check'(fn _ => realPath "." = getDir ());
  94. val test8b = 
  95.     check'(fn _ => realPath "testlink" = getDir() ^ "/README");
  96. val test8c = (realPath "testcycl" seq "WRONG")
  97.           handle OS.SysErr _ => "OK" | _ => "WRONG";
  98. val test8d = (realPath "testbadl" seq "WRONG")
  99.           handle OS.SysErr _ => "OK" | _ => "WRONG";
  100.  
  101. val test9a = 
  102.     check'(fn _ => 
  103.        setTime ("README", SOME (Time.realToTime 1E6)) = ());
  104. val test9b = 
  105.     check'(fn _ => modTime "README" = Time.realToTime 1E6);
  106.     
  107. val test10a = (remove "testdir" seq "WRONG")
  108.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  109. val test10b = 
  110.     check'(fn _ => 
  111.        rename{old = "testdir", new = "testdir2"} = ());
  112. val test10c = 
  113.     check'(fn _ => isDir "testdir2");
  114.  
  115. val test11a = 
  116.     check'(fn _ => not (access ("testdir", [])));
  117. val test11b = 
  118.     check'(fn _ => access("testlink", []));
  119. val test11c = 
  120.     check'(fn _ => not (access("testbadl", [])));
  121.  
  122. val test12a = 
  123.     check'(fn _ => isLink "testcycl" 
  124.        andalso isLink "testlink"
  125.        andalso isLink "testbadl");
  126. val test12b = 
  127.     check'(fn _ => not (isLink "testdir2"
  128.             orelse isLink "README"));
  129. val test12c = (isLink "exists.not" seq "WRONG")
  130.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  131.  
  132. val test13a = 
  133.     check'(fn _ => readLink "testcycl" = "testcycl");
  134. val test13b = 
  135.     check'(fn _ => readLink "testlink" = "README");
  136. val test13c = 
  137.     check'(fn _ => readLink "testbadl" = "exists.not");
  138. val test13d = (readLink "testdir2" seq "WRONG")
  139.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  140. val test13e = (readLink "exists.not" seq "WRONG")
  141.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  142.  
  143. val test14 = (tmpName{dir=NONE, prefix=NONE} seq "OK");
  144.  
  145. val _ = rmDir "testdir2";
  146. end
  147.